package com.camartsApp.controller;

import com.camartsApp.dto.PhotoListInfoDTO;
import com.camartsApp.service.IPhotoListService;
import com.camartsApp.common.ResultVO;
import com.camartsApp.Util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/photo-list")
public class PhotoListController {

    @Autowired
    private IPhotoListService photoListService;

    // 查询全站最新
    @GetMapping("/recent")
    public ResultVO getRecentPhotos(@RequestParam(defaultValue = "1") int pageNum,
                                    @RequestParam(defaultValue = "6") int pageSize) {
        if (pageNum > 3) pageNum = 3;
        if (pageSize > 6) pageSize = 6;
        List<PhotoListInfoDTO> list = photoListService.getRecentPhotos(pageNum, pageSize);
        return Response.OkByData(list);
    }

    // 查询指定用户最新
    @GetMapping("/api/recent/{userId}")
    public ResultVO getRecentPhotosByUserId(@PathVariable String userId,
                                            @RequestParam(defaultValue = "1") int pageNum,
                                            @RequestParam(defaultValue = "6") int pageSize) {
        if (pageNum > 3) pageNum = 3;
        if (pageSize > 6) pageSize = 6;
        List<PhotoListInfoDTO> list = photoListService.getRecentPhotosByUserId(userId, pageNum, pageSize);
        return Response.OkByData(list);
    }

    // 查询全站点赞最高的图片
    @GetMapping("/hottest")
    public ResultVO getHottestPhoto(@RequestParam(defaultValue = "1") int pageNum,
                                    @RequestParam(defaultValue = "6") int pageSize) {
        if (pageNum > 3) pageNum = 3;
        if (pageSize > 6) pageSize = 6;
        List<PhotoListInfoDTO> photos = photoListService.getHottestPhoto(pageNum, pageSize);
        return Response.OkByData(photos);
    }

    // 查询指定用户点赞最高的图片
    @GetMapping("api/user-hottest/{userId}")
    public ResultVO getUserHottestPhotos(@PathVariable String userId,
                                         @RequestParam(defaultValue = "1") int pageNum,
                                         @RequestParam(defaultValue = "6") int pageSize) {
        if (pageNum > 3) pageNum = 3;
        if (pageSize > 6) pageSize = 6;
        List<PhotoListInfoDTO> list = photoListService.getUserHottestPhotos(userId, pageNum, pageSize);
        return Response.OkByData(list);
    }
}